﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data.Common;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            string connectionstring = "server = .;database=hong;uid=sa;Pwd=wang20010109";

            SqlConnection sqlconnnection = new SqlConnection(connectionstring);

            sqlconnnection.Open();

            var sqlcommandstring = "select * from Student2";
            //声明指令对象
            SqlCommand sqlcmmand = new SqlCommand(sqlcommandstring, sqlconnnection);
            var sdr = sqlcmmand.ExecuteReader();
            Console.WriteLine("{0}\t{1}\t{2}", "姓名", "编号", "性别");
            while (sdr.Read())
            {

                Console.WriteLine("{0}\t{1}\t{2}", sdr["studentname"], sdr["no"], sdr["sex"]);

            }
            sqlconnnection.Close();
        }
        static void Main(string[] args)
        {
           
            string connectionstring = "server = .;database=hong;uid=sa;Pwd=wang20010109";
          
            SqlConnection sqlconnnection = new SqlConnection(connectionstring);
        
            sqlconnnection.Open();
        
            var sqlcommandstring = "select * from Student2";
            //声明指令对象
            SqlCommand sqlcmmand = new SqlCommand(sqlcommandstring, sqlconnnection);
             var sdr = sqlcmmand.ExecuteReader();
            Console.WriteLine("{0}\t{1}\t{2}","姓名","编号","性别");
            while (sdr.Read())
            {
               
              Console.WriteLine("{0}\t{1}\t{2}",sdr["studentname"],sdr["no"],sdr["sex"]);    

            }
            sqlconnnection.Close();
            SqlDataAdapter dataadapter = new System.Data.SqlClient.SqlDataAdapter(sqlcommandstring, selectConnection);
            datable datatable = new datable();
            dataadapter.Fill(dataTable);
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("{0}\t{1}\t{2}", "姓名", "编号", "性别");
            for (int i = 0; i <= dataTable.Rows; i++)
            {
                Console.WriteLine("{0}\t{1}\t{2}", dataTable.Rows[i]["studentname"], dataTable.Rows[i]["no"], dataTable.Rows[i]["sex"]);

            }
            Console.WriteLine(  );
        }





        public static System.Data.SqlClient.SqlConnection selectConnection { get; set; }

        public static System.Data.DataTable dataTable { get; set; }
    }



    }

